from . import socket_client, tlv_parser, con_url, error


class TestMain(object):
    sc = socket_client.SocketClient()
    tp = tlv_parser.TlvParse()
    cu = con_url.ConUrl()
    err = error.Error()

    def test(self, serverInfo, data, secret, url):
        if serverInfo["ip"] is None or serverInfo["port"] is None:
            return
        if data["username"] is None or data["pwd"] is None:
            return
        if url is None:
            return
        # 返回true说明可以不能上网，false说明可以上网
        if not self.cu.con_url(url):
            # 执行联网动作
            if self.sc.online(serverInfo, data, secret):
                error.err_print("online")
        else:
            # 执行踢网动作
            if self.sc.offline(serverInfo, data, secret):
                error.err_print("offline")


if __name__ == "__main__":
    serverInfo = {}
    serverInfo["ip"] = "192.168.1.199"
    serverInfo["port"] = "2000"
    data = {}
    data["username"] = "zyt"
    data["pwd"] = "123456"
    secret = "123456789"
    url = "http://xueshu.baidu.com/"
    obj_tlv = TestMain()
    obj_tlv.test(serverInfo, data, secret, url)
